package sg.edu.nus.iss.vmcs.entity;

import sg.edu.nus.iss.vmcs.entity.simuator.SimulatorCashStore;

public abstract class CashStore1 extends Store1 {

	 public static CashStore1 getInstance(String storeType){
		 CashStore1 cashStore = null;
		 if(storeType.equals("simulator")){
			 cashStore= SimulatorCashStore.getInstance();
			 cashStore.processStore();
		 }else{
			 System.out.println("Given storeType is not valid option "+storeType);
		 }
		 return cashStore;
	 }
	 protected abstract void processStore() ;
	 
	public int findCashStoreIndex (Coin c) {
		int size = getStoreSize();
		for (int i = 0; i < size; i++) {
			StoreItem item = (CashStoreItem) getItem(i);
			Coin current = (Coin) item.getContent();
			if (current.getWeight() == c.getWeight())
				return i;
		}
		return -1;
	}

	/**
	 * @param weight the weight of the coin
	 * @return a Coin object if the weight is valid
	 * return a null value if the weight does not match any of the Coins' weight in the CashStore 
	 */
	public Coin findCoinByWeight(double weight){
		StoreItem[] storeItems = getItems();
		if (storeItems == null)
			return null;
		
		for (int i = 0; i < storeItems.length; i++){
			Coin coin = (Coin) storeItems[i].getContent();
			if (coin.getWeight() == weight)
				return coin;
		}
		return null;
	}

}
